#ifndef __RS232_INTERFACE_H
#define __RS232_INTERFACE_H



#define RS232_SPEED     115200

#define USE_DEBUG_MODE 1

#define NEW_LINE "\n"

#define DBG(...) { rf_printf(__VA_ARGS__); }
#define DBG_FATAL(fmt,...) { rf_printf("[FATAL](%s|%s|%d)" fmt NEW_LINE, __func__, __FILE__, __LINE__, ##__VA_ARGS__); }
#define DBG_ERROR(fmt,...) { rf_printf("[ERROR](%s|%s|%d)" fmt NEW_LINE, __func__, __FILE__, __LINE__, ##__VA_ARGS__); }
#define DBG_WARN(fmt,...) { rf_printf("[WARN](%s|%s|%d)" fmt NEW_LINE, __func__, __FILE__, __LINE__, ##__VA_ARGS__); }
#define DBG_INFO(fmt,...) { rf_printf("[INFO](%s|%s|%d)" fmt NEW_LINE, __func__, __FILE__, __LINE__, ##__VA_ARGS__); }
#define DBG_DEBUG(fmt,...) { rf_printf("[DEBUG](%s|%s|%d)" fmt NEW_LINE, __func__, __FILE__, __LINE__, ##__VA_ARGS__); }
#define DBG_TRACE(fmt,...) { rf_printf("[TRACE](%s|%s|%d)" fmt NEW_LINE, __func__, __FILE__, __LINE__, ##__VA_ARGS__); }


#define STATE_INIT 0
#define STATE_HD0 1
#define STATE_HD1 2
#define STATE_FILE_NAME_SZ 3
#define STATE_FILE_NAME 4
#define STATE_FSIZE0 5
#define STATE_FSIZE1 6
#define STATE_FSIZE2 7
#define STATE_FSIZE3 8

#define STATE_CRC0 9
#define STATE_CRC1 10
#define STATE_CRC2 11
#define STATE_CRC3 12

#define STATE_SEND_SYNC 13
#define STATE_RCV_FILE 14
#define STATE_RCV_END 15

#define RCV_ERR_NO 0
#define RCV_ERR_HD0 -1
#define RCV_ERR_HD1 -2
#define RCV_WRONG_CRC -3
#define RCV_ERR_LOST_DATA -4

#define USART_RX_READY()	(USART_GetITStatus(RS232_USART, USART_IT_RXNE) != RESET)
#define USART_SEND(c)		USART_SendData(RS232_USART, c)
#define USART_READ()		USART_ReceiveData(RS232_USART)

#define RS232_INIT()		rs232_init()
#define RS232_USART			USART3
#define	RS232_USART_CLK()	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART3, ENABLE)
#define RS232_USART_IRQ		USART3_IRQn
#define RS232_USART_TX_PORT	GPIOA
#define RS232_USART_TX_PIN	GPIO_Pin_9
#define RS232_USART_RX_PORT	GPIOA
#define RS232_USART_RX_PIN	GPIO_Pin_10


//#if (USE_RS232 == 1)
void rf_putc(char c);
void rf_puts(const char* str);
void rf_printf(const char* str, ...);
//#endif

void rs232_proc(void);


#endif /* RS232_INTERFACE_H_ */
